package top.zuli.package03.exam01;

/**
 * 1.工厂设计模式
 */
//1.定义英雄规范
public interface Hero {
    //1.购买英雄
    public void buyHero();
    //2.使用英雄
    public void userHero();
    public static void main(String[] args) {
        Hero hero = HeroFactory.getHero("后裔");
        hero.buyHero();
        hero.userHero();
        Hero hero2 = HeroFactory.getHero("程咬金");
        hero2.buyHero();
        hero2.userHero();
    }

}
//2.定义具体英雄
class HouYi implements Hero{
    @Override
    public void buyHero() {
        System.out.println("5000金币可以购买后裔");
    }

    @Override
    public void userHero() {
        System.out.println("攻速型射手");
    }

}
//3.定义具体英雄
class ChengYaojin implements Hero{

    @Override
    public void buyHero() {
        System.out.println("8800购买程咬金");

    }

    @Override
    public void userHero() {
        System.out.println("坦克回血");
    }

}
//3.编写生产英雄工厂类
class HeroFactory{
    public static Hero getHero(String name) {
        if(name.equals("后裔")) {
            return new HouYi();
        }
        if(name.equals("程咬金")) {
            return new ChengYaojin();
        }
        return null;
    }

}

